/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.xcdh.learn.controller;


import com.xcdh.commons.controller.BaseController;
import com.xcdh.domain.vo.R;
import com.xcdh.learn.entity.ContentEx;
import com.xcdh.learn.service.IContentExService;
import com.xcdh.learn.util.TreeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * bigboss 控制器
 *
 *
 * @since 2022-05-30
 */
@RestController
@RequestMapping("/contentex")
public class ContentExController extends BaseController<ContentEx , IContentExService> {
	@Autowired
	private IContentExService contentExService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	public R<ContentEx> detail(ContentEx contentEx) {
		ContentEx detail = contentExService.getById(contentEx.getId());
		return R.okData(detail);
	}




	@Override
	@GetMapping("/list")
	public R<List<ContentEx>> list(ContentEx contentEx) {
		List<ContentEx> contentExes = contentExService.listContent(contentEx);
		List<ContentEx> tree = TreeUtil.buildTree(contentExes);
		return R.okData(tree);
	}


	/**
	 * 新增或修改 bigboss
	 */
	@PostMapping("/submit")
	public R submit(@RequestBody ContentEx contentEx) {
		return R.result(contentExService.saveOrUpdate(contentEx));
	}





}
